package com.mercury.ec.module.air.enums;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import com.mercury.ec.framework.common.core.IntArrayValuable;
import com.mercury.ec.framework.common.enums.CardTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 机票订单类型枚举
 *
 * @author hesx
 */
@Getter
@AllArgsConstructor
public enum AirOrderTypeEnum implements IntArrayValuable {

    SALE(1, "销售单"),
    CHANGE(2, "改签单"),
    RETURN(3, "退票单"),
    ADJUST(4, "调账单"),
    ;


    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(AirOrderTypeEnum::getType).toArray();

    public static final String DICT_TYPE = "air_order_type";

    /**
     * 值
     */
    private final Integer type;
    /**
     * 名称
     */
    private final String name;

    @Override
    public int[] array() {
        return ARRAYS;
    }

    public static AirOrderTypeEnum getByType(int type) {
        return ArrayUtil.firstMatch(o -> o.getType().equals(type), values());
    }

    public static AirOrderTypeEnum getInstance(Integer type){
        return Arrays.stream(values()).filter(t -> t.getType().equals(type)).findFirst()
                .orElseThrow(() -> new IllegalArgumentException("未知的订单类型,请联系管理员..."));
    }

    public static boolean isSale(Integer type) {
        return ObjUtil.equal(SALE.type, type);
    }
    public static boolean isChange(Integer type) {
        return ObjUtil.equal(CHANGE.type, type);
    }
    public static boolean isReturn(Integer type) {
        return ObjUtil.equal(RETURN.type, type);
    }
    public static boolean isAdjust(Integer type) {
        return ObjUtil.equal(ADJUST.type, type);
    }
}
